package com.csea.app.controller;

import com.csea.app.model.vo.idiom.*;
import com.csea.app.service.UserIdiomService;
import com.csea.common.aspect.ApiOperationLog;
import com.csea.common.domain.dos.PublicIdiomDo;
import com.csea.common.utils.Response;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/app/idiom")
@Tag(name = "用户词语管理")
public class UserIdiomController {

    @Autowired
    private UserIdiomService userIdiomService;

    @GetMapping("/{id}")
    @ApiOperationLog(description = "获取用户成语详情")
    @Operation(summary = "获取成语详情")
    public Response<UserIdiomRspVO> getById(@PathVariable Integer id) {
        return userIdiomService.getUserIdiomById(id);
    }

    @PostMapping("/add")
    @Operation(summary = "添加用户成语")
    @ApiOperationLog(description = "创建用户成语")
    public Response<Boolean> create(@RequestBody @Validated AddUserIdiomReqVO reqVO) {
        return userIdiomService.saveUserIdiom(reqVO);
    }

    @PostMapping("/edit/baseInfo")
    @Operation(summary = "更新成语基本信息")
    @ApiOperationLog(description = "更新成语基本信息")
    public Response<Boolean> update(@RequestBody @Validated UpdateUserIdiomBaseInfoReqVO reqVO) {
        return userIdiomService.updateUserIdiomBaseInfo(reqVO);
    }

    @PostMapping("/delete/{id}")
    @Operation(summary = "删除用户成语")
    @ApiOperationLog(description = "删除用户成语")
    public Response<Boolean> delete(@PathVariable Integer id) {
        return userIdiomService.deleteUserIdiom(id);
    }

    @GetMapping("/list/{repositoryId}")
    @Operation(summary = "查询词库成语")
    @ApiOperationLog(description = "查询词库成语")
    public Response<List<UserIdiomRspVO>> listByRepository(@PathVariable Integer repositoryId) {
        return userIdiomService.listByRepository(repositoryId);
    }

    @PostMapping("/edit/operateInfo")
    @Operation(summary = "更新词语操作信息")
    @ApiOperationLog(description = "更新词语操作信息")
    public Response<Boolean> updateOperateInfo(@RequestBody @Validated UpdateUserIdiomOperateInfoReqVO reqVO) {
        return userIdiomService.updateOperateInfo(reqVO);
    }

    @PostMapping("/complexSearch")
    @Operation(summary = "复合查询成语")
    @ApiOperationLog(description = "复合查询成语")
    public Response<List<UserIdiomRspVO>> searchIdioms(@RequestBody @Validated ComplexSearchReqVO reqVO) {
        return userIdiomService.searchIdiomsByKeyword(reqVO.getKeyword());
    }

    @GetMapping("/search/coze/{keyword}")
    @ApiOperationLog(description = "Coze解析词语")
    @Operation(summary = "Coze解析词语")
    public Response<List<UserIdiomRspVO>> searchByCoze(@PathVariable String keyword) {
        return userIdiomService.searchIdiomByCoze(keyword);
    }

    @GetMapping("/statsCount")
    @Operation(summary = "获取用户卡片统计")
    @ApiOperationLog(description = "获取用户卡片统计")
    public Response<UserCardStatsRspVO> getCardStats() {
        return userIdiomService.getUserCardStats();
    }
}